package com.xafc.demo.sys.dao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xafc.demo.sys.model.dto.MenuDto;
import com.xafc.demo.sys.model.dto.RoleDto;
import com.xafc.demo.sys.model.dto.UserDto;
import com.xafc.demo.sys.model.entity.User;
import com.xafc.demo.sys.model.query.UserPageQuery;
import org.apache.ibatis.annotations.Param;

import java.util.List;

//@Mapper
public interface UserMapper extends BaseMapper<User> {

    /**
     * 根据用户名查询用户
     * @param username
     * @return
     */
    User selectUserByUsername(@Param("username") String username);

    /**
     * 分页返回用户列表信息
     *
     * @param page  分页参数
     * @param wrapper 条件构造器
     * @return 用户列表数据
     */
//    @Select(
//            "   select" +
//                    "       u.id," +
//                    "       u.name," +
//                    "       u.mobile," +
//                    "       u.username," +
//                    "       u.password," +
//                    "       u.salt," +
//                    "       u.dept," +
//                    "       u.manage_dept," +
//                    "       u.part_dept," +
//                    "       u.role," +
//                    "       u.last_login," +
//                    "       u.last_ip," +
//                    "       u.back_water," +
//                    "       u.create_time," +
//                    "       u.update_time," +
//                    "       u.entry_time," +
//                    "       u.dimission_time," +
//                    "       u.status," +
//                    "       u.company" +
//                    "   from" +
//                    "       sys_user as u" +
//                    "   ${ew.customSqlSegment}"
//    )
    List<UserDto> selectUserListByWrapper(Page<UserDto> page, @Param(Constants.WRAPPER) QueryWrapper wrapper);

    /**
     * 分页返回用户列表信息
     *
     * @param page  分页参数
     * @param query 过滤条件
     * @return 用户列表数据
     */
    List<UserDto> selectUserList(Page<UserDto> page, @Param("query") UserPageQuery query);

    /**
     * 获取用户的所有的角色
     */
    List<RoleDto> selectUserRoles(@Param("userId") Integer userId);

    /**
     * 获取用户的所有的权限
     */
    List<MenuDto> selectUserPerms(@Param("userId") Integer userId);

}
